home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10867 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: Ra.MsState.Edu!mhp1
  2. From: mhp1@Ra.MsState.Edu (Michael H Price II)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: array of struct
  5. Date: 20 Mar 1996 09:35:00 -0600
  6. Organization: Mississippi State University
  7. Message-ID: <mhp1.827335696@Ra.MsState.Edu>
  8. References: <Pine.LNX.3.91.960319173746.16221A-100000@larry.inf.net>
  9. NNTP-Posting-Host: ra.msstate.edu
  10. X-Newsreader: NN version 6.5.0 #2 (NOV)
  11.  
  12. Lawrence O'Leary <larry@larry.inf.net> writes:
  13.  
  14. > What I want to do is create each record in the array by reading a line
  15. > from a file and storing each field of the line into the record.  Do this
  16. > for every line in the file and then where done.  What I need to do is
  17. > create the array of the struct for the exact number of lines that are in
  18. > the file.  This way I won't be wasting memory and I won't have to worry
  19. > about not having enough records to store the lines into.
  20.  
  21. Currently using ISO C this is not possible.  In future revisions of C you
  22. can have dynamically sized arrays like you currently can using GNU'c C
  23. compiler.  However, while you can specify the size at runtime, you must
  24. still specify a size -- it won't grow dynamically.  To do what you want you
  25. would first have to determine the number of lines in the file, then
  26. allocate the array, then read in the lines.  Of course, you also have to
  27. use a compiler (like GNU's gcc) that allows dynamic arrays.
  28.  
  29. Michael
  30.  
  31. P.S.  There are other things you can do using other data structures that
  32.       would still allow quick access to any record.
  33.